#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct treenode
{
    char val;
    struct treenode* left;
    struct treenode* right;
}TRnode;

void PreOrder(TRnode* root)
{
    if (root == NULL)
    {
        return;
    }
    printf("%c ", root->val);
    PreOrder(root->left);
    PreOrder(root->right);
}
TRnode* creattree(char* data, int* size)
{
    if (data[*size] == '#')
    {
        (*size)++;
        return NULL;
    }
    TRnode* root = (TRnode*)malloc(sizeof(TRnode));
    root->val = data[(*size)++];
    root->left = creattree(data, size);
    root->right = creattree(data, size);
    return root;
}
void inordeprint(TRnode* root)
{
    if (root == NULL)
        return;
    inordeprint(root->left);
    printf("%c ", root->val);
    inordeprint(root->right);
}
int main() {
    char data[100] = { 0 };
    while (gets(data) != EOF)
    {
        int size = 0;
        TRnode* ret = creattree(data, &size);
        inordeprint(ret);
        printf("\n");
    }
    return 0;
}